#ifndef TEXTURE_RENDER_H
#define TEXTURE_RENDER_H

#include "RenderObject.h"

struct SVertexData
{
    SVertexData( )
    {
        count = 0;
        pData = NULL;
        bufferlen = 0;
        vertexsize = 0;
    }
    ~SVertexData( )
    {
        if( pData )
            free( pData );
    }
    void Resize( uint32 newsize )
    {
        if( newsize <= bufferlen )
            return;
        void *pNewData = malloc( newsize );
        if( pData )
        {
            memcpy( pNewData, pData, bufferlen );
            free( pData );
        }
        pData = pNewData;
        bufferlen = newsize;
    }
    uint32 RestBuffer( )
    {
        return bufferlen - count * vertexsize;
    }
    void *CurPosition( )
    {
        return (char*)pData + count * vertexsize;
    }
    uint32 count;
    uint32 vertexsize;
    uint32 bufferlen;
    void *pData;
};

class CTextureRender:public CRenderObject
{
public:
    CTextureRender();
    ~CTextureRender();
    virtual void Render( );
    void LoadTexture( PCTSTR filename, int colorkey = 0 );
    void SetTextureID( int id );
    int  GetTextureID( );
    void SetUV( float u1, float v1, float u2, float v2 );

    void ClearVertexData( );
    void AddVertexData( void *data, uint32 count );

protected:
    int m_textureid;
    SVertexData m_vdata;
    float m_u1;
    float m_v1;
    float m_u2;
    float m_v2;
};

#endif